package sorting_numbers;

import java.util.Scanner;

public class Align {
	String str;

	static int total_switches;
	
	public Align(String str) {

		this.str = str;
		// System.out.println(str);
	}

	void doAscend(String str) {
		int[] iarr = toIntArray(str);

		int count = 1;
		do {
			
			count = 0;
			for (int i = 0; i < iarr.length; i++) {
				// we need to do this as long as the count is > 0
				
				// completes a complete round of traversing the array

				try {
					Thread.sleep(1000);
					if (iarr[i] > iarr[i + 1]) {
						int temp = iarr[i];
						iarr[i] = iarr[i + 1];
						iarr[i + 1] = temp;
						count++;
						total_switches++;

						// System.out.println("inside  :" + count);
					}

				} catch (Exception e) {
					System.out.println("in the catch");
					// count = 0;
				}
				System.out.println(iarr[i] + " " + count);

			}
		}while (count != 0);

	}

	int[] toIntArray(String str) {

		int[] iarr = new int[str.length()];
		for (int i = 0; i < str.length(); i++) {

			char temp = str.charAt(i);
			iarr[i] = temp - 48;

		}
		return iarr;

	}

}
